﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace Security.Authorizations
{
    /// <summary>
    ///  Role Provider to uses with Authorization Provider, 
    ///  to make compatible with native .Net components supporting RoleProvider
    /// </summary>
    public class AuthorizationRoleProvider : RoleProvider
    {
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            Authorizations.AddUsersToRoles(usernames, roleNames);
        }

        public override string ApplicationName
        {
            get
            {
                return Authorizations.ApplicationName;
            }
            set
            {
                Authorizations.ApplicationName = value;
            }
        }

        public override void CreateRole(string roleName)
        {
            Authorizations.CreateRole(roleName);
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            return Authorizations.DeleteRole(roleName, throwOnPopulatedRole, null);
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            return Authorizations.FindUsersInRole(roleName, usernameToMatch);
        }

        public override string[] GetAllRoles()
        {
            return Authorizations.GetAllRoles();
        }

        public override string[] GetRolesForUser(string username)
        {
            return Authorizations.GetRolesForUser(username);
        }

        public override string[] GetUsersInRole(string roleName)
        {
            return Authorizations.GetUsersInRole(roleName);
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            return Authorizations.IsUserInRole(username, roleName);
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            Authorizations.RemoveUsersFromRoles(usernames, roleNames);
        }

        public override bool RoleExists(string roleName)
        {
            return Authorizations.RoleExists(roleName);
        }
    }
}
